/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package modele;

import exception.EmployeeLoginExists;
import exception.EmployeeAlreadyInDepartment;
import java.util.Collection;
import java.util.HashSet;

/**
 *
 * @author Alex
 */
public class Department {
    protected Integer idDepartment;
    protected String name;
    protected Collection<Employee> employees;

    public Department(String name) {
        this.name = name;
        employees = new HashSet<>();
    }

    public Collection<Employee> getEmployees() {
        return employees;
    }

    public void setEmployees(Collection<Employee> employees) {
        this.employees = employees;
    }
    
    public Integer getIdDepartment() {
        return idDepartment;
    }

    public void setIdDepartment(Integer idDepartment) {
        this.idDepartment = idDepartment;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
    
    public Integer getNbEmployees() {
        return employees.size();
    }
    
    public void addEmployee(Employee e) throws EmployeeLoginExists,
            EmployeeAlreadyInDepartment {
        Boolean result;
        for (Employee emp : this.employees)
            if (e.getLogin().equals(emp.getLogin() ) )
                throw new EmployeeLoginExists(e.getLogin());
        result = this.employees.add(e);
        if (!result)
            throw new EmployeeAlreadyInDepartment(e, this);
    }
    
    public void delEmployee(Employee e) {
        /* Deal with exceptions (not found, etc.) */
        this.employees.remove(e);
    }
}
